package com.kjlink.internal.report4vue.common.service;

import cn.xuqiudong.common.base.model.BaseResponse;
import cn.xuqiudong.common.base.vo.Select2VO;
import cn.xuqiudong.common.util.CommonUtils;
import com.kjlink.internal.report4vue.base.enums.SelectTypeEnums;
import com.kjlink.internal.workreport.base.enums.UserType;
import com.kjlink.internal.workreport.group.model.Group;
import com.kjlink.internal.workreport.group.service.GroupService;
import com.kjlink.internal.workreport.helper.SessionHelper;
import com.kjlink.internal.workreport.project.service.ProjectService;
import com.kjlink.internal.workreport.user.model.User;
import com.kjlink.internal.workreport.user.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2024-12-09 11:16
 */
@Service
public class ApiCommonService {

    @Resource
    private GroupService groupService;

    @Resource
    private ProjectService projectService;

    @Resource
    private UserService userService;


    public BaseResponse<List<Select2VO>> select(SelectTypeEnums type) {
        Integer userId = SessionHelper.currentUserId();
        switch (type) {
            case group:
                return groups();
            case project:
                return projects(null);
            case mineProject:
                return projects(userId);
            case managerProject:
                List<Select2VO> list = projectService.devManagerProject(userId);
                return BaseResponse.success(list);
            case user:
                return users();
            case managerUser:
                return managerUsers();
            default:
                return BaseResponse.success();
        }
    }

    /**
     * 用户下拉框:
     */
    private BaseResponse<List<Select2VO>> users() {
        List<Select2VO> all = userService.all();
        return BaseResponse.success(all);
    }

    /**
     * 项目经理用户下拉框
     */
    private BaseResponse<List<Select2VO>> managerUsers() {
        List<Select2VO> all = userService.managerUsers();
        return BaseResponse.success(all);
    }

    /**
     * 全部项目
     */
    private BaseResponse<List<Select2VO>> projects(Integer userId) {
        List<Select2VO> list = projectService.mineProject(userId);
        return BaseResponse.success(list);
    }

    /**
     * 全部小组
     */
    public BaseResponse<List<Select2VO>> groups() {
        List<Group> list = groupService.list(new Group().setEnable(true));
        List<Select2VO> result = CommonUtils.listFilter(list, group -> new Select2VO(group.getId(), group.getName()));
        return BaseResponse.success(result);
    }
}
